package Controllers;

import Bean.BeanClass;
import Bean.BeanPlace;
import Impl.ClassServiceImpl;
import Impl.PlaceServiceImpl;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ClassModifyController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    ClassServiceImpl classService;
	 @RequestMapping(value = "/ClassModify", method = RequestMethod.POST)
		@ResponseBody
		public JSONObject userRegister(HttpServletRequest request,@RequestBody JSONObject in) throws Exception {
		 	ApplicationContext applicationContext=(ApplicationContext)request.getSession().getServletContext().getAttribute("ctx");
	        classService=(ClassServiceImpl) applicationContext.getBean("ClassServiceImpl");
			JSONObject obj = new JSONObject();
			BeanClass aClass = new BeanClass();
			aClass.setClass_id(Integer.parseInt(in.getString("classid")));
			aClass.setClass_name(in.getString("classname"));
		 	aClass.setClass_url(in.getString("classurl"));
			aClass.setClass_price(Double.parseDouble(in.getString("classprice")));
			aClass.setNum(in.getInteger("classnum"));
			aClass.setTeacher_id(in.getString("classteacher"));
		 	aClass.setPlace_id(in.getInteger("classplace"));

			classService.classUpdate(aClass.getClass_id(),aClass.getClass_name(), aClass.getClass_url(), aClass.getNum(),aClass.getClass_price(),aClass.getTeacher_id(),aClass.getPlace_id());
			obj.put("status", "OK");
			return obj;
		}
}
